﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace TTMarketing.CameraUserControl.SanPham
{
    public partial class ucGetAll : System.Web.UI.UserControl
    {
        public String url_checkout = "https://www.nganluong.vn/advance_payment.php";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["name"]!=null)
            {
                lblTitle.Text = Request.QueryString["name"];
            }
        }

        protected void RadListView1_ItemCommand(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("Mua"))
                {
                    List<TTController.clsBSOrder> order = new List<TTController.clsBSOrder>();
                    if (Session["order"] != null)
                    {
                        order = (List<TTController.clsBSOrder>)Session["order"];
                    }
                    TTController.clsBSOrder obj = new TTController.clsBSOrder();
                    obj.ProductId = Convert.ToInt32(e.CommandArgument);
                    bool check = true;
                    for (int i = 0; i < order.Count; i++)
                    {
                        if (order[i].ProductId.Equals(obj.ProductId))
                        {
                            order[i].Count = order[i].Count + 1;
                            check = false;
                            break;
                        }
                    }
                    if (check)
                    {
                        obj.Count = 1;
                        order.Add(obj);
                    }
                    Session["order"] = order;
                    Response.Redirect("~/gio-hang.aspx");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        protected void RadListView1_PreRender(object sender, EventArgs e)
        {
            foreach (RadListViewDataItem item in RadListView1.Items)
            {
                HiddenField hi = (HiddenField)item.FindControl("hfID");
                HyperLink ss = (HyperLink)item.FindControl("btnSosanh");
                ss.Attributes.Add("onclick", "openNewWindow('" + hi.Value + "'); return false;");
                ImageButton btnNL = (ImageButton)item.FindControl("btnNganLuong");
                HiddenField prices = (HiddenField)item.FindControl("hfPrice");
                HiddenField h = (HiddenField)item.FindControl("hfName");
                //Lập trinh nút thanh toán ngân lượng
                String receiver = "duyhung862000@yahoo.com";
                String comments = h.Value;
                String return_url = "https://tantinh.net/";
                String price = prices.Value;
                String product = h.Value;
                this.url_checkout += "?receiver=" + receiver + "&comments=" + comments + "&return_url=" + return_url + "&product=" + product + "&price=" + price;
                btnNL.PostBackUrl = this.url_checkout;
            }
        }
    }
}